<?php
namespace Hive\Ressource;
/**
 * Contact Partner Object. 
 * 
 * This object represents the link between a contact and a user in our case.
 * 
 *
 * @author Xavier VILAIN
 * @package Hive\Ressource\Partner
 * @property int 	$ressource_id 	Id of the parent customer
 * @property string $role			Role of the contact
 * @property int 	$partnerid		Id of the contact partner
 * @property bool 	$defaultflag	Default Flag
 * @property string $status			Partner Status
 * @property datetime $cdate		Creation Date
 * @property int	$cname			Id of the creator
 * @property datetime $udate		Last change Date 
 * @property int	$uname			Id of the last author
 */
class Partner extends \Fox\Object {
	
	/**
	 * Contact Parent
	 * @var string
	 */
	const LINK_RESSOURCE = 'ressource';

	/**
	 * 
	 * Mission Responsible 
	 * @var string
	 */
	const ROLE_RESPONSIBLE = 'RP';
		
	/**
	 * 
	 * Default Status for each parnter
	 * @var int
	 */
	const STATUS_DEFAULT = '1';
	
	/**
	 * 
	 * @return Object Source Data
	 */
	public function source()
	{
		return \Fox\Dao::load(\User::className(),$this->partnerid);
	}
	
	/**
	 * (non-PHPdoc)
	 * @see includes/classes/Fox/Object/Versioned::beforeVersionUpdate()
	 */
	protected function beforeCreate() {
		$this->cdate = self::sqlDateTime(time());
		$this->cname = \User::current()->getId();
		$this->udate = $this->cdate;
		$this->uname = $this->cname;
	}
	
	/**
	 * (non-PHPdoc)
	 * @see includes/classes/Fox/Object/Versioned::beforeVersionUpdate()
	 */
	protected function beforeUpdate($changed) {
		if($changed) {
			$this->udate = self::sqlDateTime(time());
			$this->uname = \User::current()->getId();
		}
		return $changed;
	}
}
\Fox\Dao::infos(
	Partner::className(),
	new \Fox\Object\Info('ressource_partners', \Fox\Databases::DB_APP)
);